package com.RedRiver.hospitalsystem.personal_service.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.RedRiver.hospitalsystem.personal_service.infra.mapper.WorkloadMapper;
import com.RedRiver.hospitalsystem.personal_service.infra.model.Worker;
import com.RedRiver.hospitalsystem.personal_service.infra.model.Workload;
import com.RedRiver.hospitalsystem.personal_service.service.Form.WorkloadForm;
import com.RedRiver.hospitalsystem.personal_service.service.Form.WorkloadPageForm;
import com.RedRiver.hospitalsystem.personal_service.service.WorkloadService;
import com.RedRiver.hospitalsystem.personal_service.service.info.WorkerPageInfo;
import com.RedRiver.hospitalsystem.personal_service.service.info.WorkloadPageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.xml.transform.Result;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@Service
public class WorkloadServiceImpl extends ServiceImpl<WorkloadMapper, Workload> implements WorkloadService {

    @Override
    public IPage<WorkloadPageInfo> findPageWorkload(WorkloadPageForm form) {
        Page<Workload> workloadPageInfo = new Page<>();
        workloadPageInfo = this.baseMapper.selectPage(new Page<>(form.getPage() == 0 ? 1 : form.getPage(),
                form.getPageSize() == 0 ? 2 : form.getPageSize()),null);
        List<Workload> workerInfoList = workloadPageInfo.getRecords();
        List<WorkloadPageInfo> workerPageInfoList = BeanUtil.copyToList(workerInfoList, WorkloadPageInfo.class);
        Page<WorkloadPageInfo> page = new Page<>();
        page.setRecords(workerPageInfoList);
        page.setCurrent(workloadPageInfo.getCurrent());
        page.setSize(workloadPageInfo.getSize());
        page.setTotal(workloadPageInfo.getTotal());
        return page;
    }

    @Override
    public Result updateWorkload(WorkloadForm workloadForm) {
        return null;
    }

}
